package org.company.ci.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.company.ci.domain.Proveedor;
import org.company.ci.services.ProveedorService;
import org.company.ci.services.ServiceFinder;

/**
 * Servlet implementation class EliminarProveedorServlet
 */
public class EliminarProveedorServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	private ServletConfig config;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EliminarProveedorServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		this.config = config;
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ProveedorService proveedorService = (ProveedorService) ServiceFinder.getBean(config.getServletContext(),"proveedorService");
		
		String id = request.getParameter("id");
		
		Proveedor prov = new Proveedor();
		
		prov.setIdProveedor(new Long(id));
		
		
		PrintWriter pw = response.getWriter();
		
		try {
			proveedorService.deleteProveedor(prov);
			
			pw.println(0);
			
		} catch (Exception e) {
			pw.println(e.getMessage());
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}